from bokeh.models import ColumnDataSource
from bokeh.io import output_notebook, show
p = figure(plot_width=300, plot_height=300)
# x and y are numpy arrays
x = np.linspace(0, 10, 101)
y = np.exp(x)
# circle glyph takes the numpy array outputs
p.circle(x, y)
output_notebook()
show(p)
print(type(x))
print(type(y))
from bokeh.plotting import figure
from bokeh.io import output_notebook, show
ghg = building_data['GHG_Emissions'] # x-values
sqft = building_data['Gross_Sq_Ft'] # y-values
# Set up the figure
p = figure(plot_width=500,
plot_height=300,
x_axis_label='Greenhouse Gas Emissions',
y_axis_label='Gross Square Feet')
p.circle(ghg, sqft)
output_notebook()
show(p)
print(type(ghg))
print(type(sqft))
ColumnDataSourceColumnDataSource is the main data structure in bokeh.ColumnDataSource has a data attribute that matches a string name to a sequence of data.table = pd.DataFrame(data=[['Greg', 2, 68], ['Tim', 4, 70]],
columns=['name', 'number', 'height'])
print(table)
name number height 0 Greg 2 68 1 Tim 4 70
table = ColumnDataSource(data={
'name': ['Greg', 'Tim'],
'number': [2, 4],
'height': [68, 70],
})
table.data
{'height': [68, 70], 'name': ['Greg', 'Tim'], 'number': [2, 4]}
ColumnDataSource:# pass the pandas DataFrame building_data to ColumnDataSource function
building_cds = ColumnDataSource(building_data)
building_cds.data.keys() # the keys are the column headers from the DataFrame
dict_keys(['Property_Name', 'Address', 'ZIP', 'Tax_Parcel', 'Property_Type', 'Gross_Sq_Ft', 'Property_Uses', 'Site_EUI', 'EnergyStar_Score', 'EnergyStar_Certified', 'Year_Built', 'GHG_Emissions', 'GHG_Intensity', 'Site_Energy_Use', 'Percent_Electr', 'Percent_Gas', 'Percent_Steam', 'Water_Intensity', 'OnSite_Solar', 'Owner_Submitted_Info', 'Owner_Submitted_Link', 'built_before', 'index'])
GHG_Emissions and Gross_Sq_Ft are keys from the ColumnDataSourcebuilding_cdsfrom bokeh.plotting import figure
from bokeh.io import output_notebook, show
# Set up the figure
p = figure(plot_width=500,
plot_height=300,
x_axis_label='Greenhouse Gas Emissions',
y_axis_label='Gross Square Feet')
p.circle('GHG_Emissions', 'Gross_Sq_Ft', source=building_cds)
output_notebook()
show(p)
print(type(building_cds))
from bokeh.models import CategoricalColorMapperCategoricalColorMapper inputs:from bokeh.plotting import figure
from bokeh.io import output_notebook, show
from bokeh.models import CategoricalColorMapper
# Set up the figure
p_basic = figure(plot_width=500,
plot_height=300,
x_axis_label='Greenhouse Gas Emissions',
y_axis_label='Gross Square Feet')
# Create the CategoricalColorMapper object
color_mapper = CategoricalColorMapper(factors=['Built after 1950', 'Built before 1950'],
palette=['red', 'blue'])
p_basic.circle(x='GHG_Emissions',
y='Gross_Sq_Ft',
source=building_cds,
color=dict(field='built_before', transform=color_mapper),
legend='built_before')
output_notebook()
show(p_basic)
print(type(building_cds))
from bokeh.palettes import Colorblindfrom bokeh.plotting import figure
from bokeh.io import output_notebook, show
from bokeh.models import CategoricalColorMapper
from bokeh.palettes import Colorblind, viridis
# Set up the figure
p_cat = figure(plot_width=500,
plot_height=300,
x_axis_label='Greenhouse Gas Emissions',
y_axis_label='Gross Square Feet')
# create an list of unique values
built_before_list = list(building_cds.data['built_before'].unique())
# Create the CategoricalColorMapper object
color_mapper = CategoricalColorMapper(factors=built_before_list,
palette=Colorblind[3])
p_cat.circle(x='GHG_Emissions',
y='Gross_Sq_Ft',
source=building_cds,
color=dict(field='built_before', transform=color_mapper),
legend='built_before')
output_notebook()
show(p_cat)
print(type(building_cds))
print(Colorblind[3])
print(viridis(6))
['#0072B2', '#E69F00', '#F0E442'] ['#440154', '#404387', '#29788E', '#22A784', '#79D151', '#FDE724']
The bokeh.palettes module also has some larger palettes with 256 colors.

from bokeh.plotting import figure
from bokeh.io import output_notebook, show
from bokeh.models import CategoricalColorMapper
from bokeh.palettes import viridis, grey, inferno
# Set up the figure
p_scale = figure(plot_width=500,
plot_height=300,
x_axis_label='Greenhouse Gas Emissions',
y_axis_label='Gross Square Feet')
# create an list of unique values
built_before_list = sorted(list(building_cds.data['Year_Built'].unique()))
# Create the CategoricalColorMapper object
color_mapper = CategoricalColorMapper(factors=built_before_list,
palette=viridis(len(built_before_list))) # used a new color palette
p_scale.circle(x='GHG_Emissions',
y='Gross_Sq_Ft',
source=building_cds,
color=dict(field='Year_Built', transform=color_mapper),
# legend='Year_Built'
)
output_notebook()
show(p_scale)
print(type(building_cds))
from bokeh.layouts import row, column
layout = row(p_basic, p_cat, p_scale)
show(layout)
from bokeh.layouts import row, column
layout = column(p_basic, p_cat, p_scale)
show(layout)
from bokeh.layouts import row, column
layout = column(row(p_basic, p_cat), p_scale)
show(layout)
toolbar_location to modify